﻿using AuSys.Services.App.UserInfo.Abstractions;
using AuSys.Services.App.UserInfo.Bases;

namespace AuSys.Services.App.UserInfo
{
    public class HttpUserIdProvider
        : HttpUserClaimReader, IUserIdProvider
    {
        private Lazy<int> UserId { get; }
        public const string UserIdClaimName = "userid";
        public HttpUserIdProvider(
            IHttpContextAccessor httpContextAccessor
            ) : base(httpContextAccessor)
        {
            UserId = new(ReadUserId);
        }
        private int ReadUserId()
            => ReadClaimAsInt(UserIdClaimName);

        public int GetUserId()
            => UserId.Value;
    }
}
